<template>
    <div class="app-container">
        <header-title/>
        <el-form
            :model="queryParams"
            ref="queryForm"
            :inline="true"
            v-show="showSearch"
            label-width="85px"
        >
            <el-form-item label="用户信息" prop="keyword">
                <el-input
                    v-model="queryParams.keyword"
                    placeholder="请输入名字/编号/手机号"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="渠道来源" prop="userChannel">
                <el-select v-model="queryParams.userChannel" filterable clearable>
                    <el-option
                        v-for="dict in dict.type.user_channel"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                    >
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="可用算力" prop="point">
                <el-input
                    v-model="queryParams.point"
                    placeholder="请输入可用算力"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <!-- <el-form-item label="用户渠道" prop="userChannel">
                <el-select v-model="queryParams.userChannel" filterable clearable>

                </el-select>
            </el-form-item> -->
            <el-form-item label="创建时间" prop="jiTime">
                <el-date-picker
                    v-model="dateRange"
                    type="datetimerange"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    @keyup.enter.native="handleQuery"
                    placeholder="选择时间">
                </el-date-picker>
            </el-form-item>
            <el-form-item class="mar-r-20">
                <el-button type="primary" icon="el-icon-search" @click="handleQuery"
                >搜索</el-button
                >
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table
            v-loading="loading"
            :data="tableList"
        >   
            <el-table-column label="注册信息" >
                <template slot-scope="scope">
                    <div class="fw-b">注册渠道：{{ selectDictLabel(dict.type.user_channel,scope.row.userChannel) || '-'}}</div>
                    <div class="color-999 mar-t-5">注册日期：{{ scope.row.createTime || "-" }}</div>
                </template>
            </el-table-column>
            <el-table-column label="客户信息">
                <template slot-scope="scope">
                    <div class="fw-b">手机号：{{ scope.row.phone || "-" }}</div>
                    <!-- <div class="color-999 mar-t-5">微信openid：{{ scope.row.wechatOpenId || "-" }}</div> -->
                    <div class="fw-b">真实姓名：{{ scope.row.userRealName || "-" }}</div>
                </template>
            </el-table-column>
            <el-table-column label="累计充值">
                <template slot-scope="scope">
                    <div class="fw-b">{{ scope.row.totalRechargeAmount || 0 }}元</div>
                </template>
            </el-table-column>
            <el-table-column label="当前可用算力">
                <template slot-scope="scope">
                    {{ scope.row.point || '-' }}
                </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right" align="center" class-name="small-padding table-handle"width="120">
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-user-solid"
                        @click="handleDetail(scope.row)"
                    >详情</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
        >
        </pagination>
        <el-drawer
            title="用户详情"
            :visible.sync="openDetail"
            direction="rtl"
            size="900px"
            append-to-body
        >
            <userDetail v-if="openDetail" :id="detailId"></userDetail>  
        </el-drawer>
    </div>
</template>
<script>
    import {listClientUser} from '@/api/operateManage/userList'
    import userDetail from './handle/detail.vue'
    export default{
        name:'UserList',
        dicts:['user_channel'],
        components: {userDetail},
        data() {
            return {
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    keyword:'',
                    point:'',
                    userChannel: '',
                   
                },
                showSearch: true,
                total: 0,
                dateRange: [],
                // 表格数据
                tableList: [],
                loading: false,
                openDetail: false,
                detailCurrent: '1',
                detailId: ''
            }
        },
        created() {
            this.getList()
        },
        methods: {
            // 查看详情
            handleDetail(row) {
                this.detailId = row.clientUserId
                this.openDetail = true
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.dateRange = [];
                this.resetForm("queryForm");
                this.handleQuery();
            },
            getList() {
                this.loading = true;
                if (this.dateRange && this.dateRange.length) {
                    this.queryParams.startTime = this.dateRange[0];
                    this.queryParams.endTime = this.dateRange[1];
                } else {
                    this.queryParams.startTime = undefined;
                    this.queryParams.endTime = undefined;
                }
                
                
                listClientUser(this.queryParams).then((response) => {
                    this.tableList = response.data.records;
                    this.total = response.data.total;
                    this.loading = false;
                });
            }
        }
    }
</script>